package java71;

import java.util.Scanner;

import java6.ArrayIntegerStack;

public class Main201521123065 {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		ArrayIntegerStack stack=new ArrayIntegerStack(sc.nextInt()); 
		int n=sc.nextInt();
		for (int i = 0; i < n; i++) {
			System.out.println(stack.push(sc.nextInt()));
		}
		System.out.println(stack.top--+","+stack.empty()+","+stack.size());	
		System.out.println(stack.toString());
		int x=sc.nextInt();		
		for (int i = 0; i < x; i++) {
			System.out.println(stack.pop());
		}
		System.out.println(stack.top--+","+stack.empty()+","+stack.size());	
		System.out.println(stack.toString());
	}
	}
}
